package com.syerit
{
	import com.syerit.controller.ApplicationStartupCommand;
	import com.syerit.model.AppDataProxy;
	import com.syerit.model.AppStateProxy;
	import com.syerit.model.ConfigProxy;
	import com.syerit.model.CookieProxy;
	import com.syerit.model.ExternalProxy;
	import com.syerit.model.LocaleProxy;
	import com.syerit.model.ProductDataProxy;
	import com.syerit.model.ServerDataProxy;
	import com.syerit.model.StartupMonitorProxy;
	
	import org.puremvc.as3.multicore.interfaces.IFacade;
	import org.puremvc.as3.multicore.patterns.facade.Facade;

	public class ApplicationFacade extends Facade implements IFacade
	{
		// Notification name constants
		//Facades
		public static const CORE_FACADE:String				="coreFacade";
		
        // application
        public static const STARTUP:String                  = "startup";
        public static const SHUTDOWN:String                	= "shutdown";

        // proxy
        public static const PROXY_LOAD_CONFIG:String		="loadConfig";
        public static const PROXY_LOAD_LOCALE:String		="loadLocale";
        public static const PROXY_LOAD_EXTERNAL:String		="loadExternal";
        public static const PROXY_LOAD_APP_STATE:String		="loadAppState";
        public static const PROXY_LOAD_COOKIE:String		="loadCookie";
        public static const PROXY_LOAD_APP_DATA:String		="loadAppData";
        public static const PROXY_LOAD_PRODUCT_DATA:String	="loadProductData";
        public static const PROXY_LOAD_SERVER_DATA:String	="loadServerData";
        //public static const LOADING_STEP:String                = "loadingStep";
        //public static const LOADING_COMPLETE:String            = "loadingComplete";
        //public static const LOAD_CONFIG_FAILED:String        = "loadConfigFailed";
        //public static const LOAD_RESOURCE_FAILED:String        = "loadResourceFailed";
        
        // command
        public static const COMMAND_STARTUP_MONITOR:String	= "StartupMonitorCommand";
        //public static const COMMAND_STARTUP_MONITOR:String	= "StartupMonitorCommand";
        //public static const COMMAND_STARTUP_MONITOR:String	= "StartupMonitorCommand";
        
        // view
        public static const APPLICATION_READY:String       	= "ApplicationReady";
        
        // common messages
        public static const ERROR_LOAD_FILE:String       	= "Could Not Load the File!";
        
        public function ApplicationFacade( key:String )
        {
            super(key);    
        }

		/**
         * Singleton ApplicationFacade Factory Method
         */
        public static function getInstance( key:String ) : ApplicationFacade 
        {
            if ( instanceMap[ key ] == null ) instanceMap[ key ] = new ApplicationFacade( key );
            return instanceMap[ key ] as ApplicationFacade;
        }
        
        /**
         * Register Commands with the Controller 
         */
        override protected function initializeController( ) : void 
        {
            super.initializeController(); 
            registerCommand( STARTUP, ApplicationStartupCommand );
        }
        /**
         * Retrieve the StartupMonitor proxy 
         */
        public function getStartupMonitorProxy():StartupMonitorProxy
        {
            return StartupMonitorProxy( ApplicationFacade.getInstance(ApplicationFacade.CORE_FACADE).retrieveProxy( StartupMonitorProxy.NAME ) );
        }
        /**
         * Retrieve the config proxy 
         */
        public function getConfigProxy():ConfigProxy
        {
            return ConfigProxy( ApplicationFacade.getInstance(ApplicationFacade.CORE_FACADE).retrieveProxy( ConfigProxy.NAME ) );
        }
    
        /**
         * Retrieve the resource proxy 
         */
        public function getLocaleProxy():LocaleProxy
        {
            return LocaleProxy( ApplicationFacade.getInstance(ApplicationFacade.CORE_FACADE).retrieveProxy( LocaleProxy.NAME ) );
        }
        /**
         * Retrieve the cookie proxy 
         */
        public function getCookieProxy():CookieProxy
        {
            return CookieProxy( ApplicationFacade.getInstance(ApplicationFacade.CORE_FACADE).retrieveProxy( CookieProxy.NAME ) );
        }
        /**
         * Retrieve the appData proxy 
         */
        public function getAppDataProxy():AppDataProxy
        {
            return AppDataProxy( ApplicationFacade.getInstance(ApplicationFacade.CORE_FACADE).retrieveProxy( AppDataProxy.NAME ) );
        }
        /**
         * Retrieve the appState proxy 
         */
        public function getAppStateProxy():AppStateProxy
        {
            return AppStateProxy( ApplicationFacade.getInstance(ApplicationFacade.CORE_FACADE).retrieveProxy( AppStateProxy.NAME ) );
        }
        /**
         * Retrieve the external proxy 
         */
        public function getExternalProxy():ExternalProxy
        {
            return ExternalProxy( ApplicationFacade.getInstance(ApplicationFacade.CORE_FACADE).retrieveProxy( ExternalProxy.NAME ) );
        }
        /**
         * Retrieve the productData proxy 
         */
        public function getProductDataProxy():ProductDataProxy
        {
            return ProductDataProxy( ApplicationFacade.getInstance(ApplicationFacade.CORE_FACADE).retrieveProxy( ProductDataProxy.NAME ) );
        }
		/**
         * Retrieve the serverData proxy 
         */
        public function getServerDataProxy():ServerDataProxy
        {
            return ServerDataProxy( ApplicationFacade.getInstance(ApplicationFacade.CORE_FACADE).retrieveProxy( ServerDataProxy.NAME ) );
        }
        /**
         * Start the application
         */
        public function startup( app:MainApp ):void
        {
            sendNotification( STARTUP, app );
        }	
	}
}